# Created by and for Qt Creator This file was created for editing the project sources only.
# You may attempt to use it for building too, by modifying this file here.

cmake_minimum_required(VERSION 3.5)
project(libmtrader VERSION 1.0 DESCRIPTION "the trading backtest")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


message(STATUS "The value of TO_INSTALL_PATH is: $ENV{TO_INSTALL_PATH}")

set (MU $ENV{TO_INSTALL_PATH})
# set (MU /ssd1/mycat/usr)
# set (MU /usr/local)
# set (MU /Users/stonego/usr)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MU}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MU}/bin)

set (LIB_INSTALL_DIR ${MU}/lib)
set (BIN_INSTALL_DIR ${MU}/bin)
set (INCLUDE_INSTALL_DIR ${MU}/include)

include_directories(
  include
  ../include
  /usr/include
  /usr/local/include
  ${MU}/include
)



link_directories(
  /usr/local/lib
  /usr/lib
  /lib
  ${MU}/lib
)


#configuration types
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
IF(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8")
  SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
ENDIF()

IF (CMAKE_SYSTEM_NAME MATCHES "Linux") 
    MESSAGE(STATUS "current platform: Linux ")
    add_definitions(-D_LINUX_)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows") 
    MESSAGE(STATUS "current platform: Windows") 
    add_definitions(-D_WINDOWS_)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin") 
    MESSAGE(STATUS "current platform: Mac OS X") 
    add_definitions(-D_MACOS_)
ELSE () 
    MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}") 
    add_definitions(-D_OTHER_)
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux") 


IF (CMAKE_BUILD_TYPE MATCHES Debug)
  message("Debug build libmttraded")

  add_definitions(-DSTONE_DEBUG=1)
  add_definitions(-DSTEP_BY_STEP=1)
  add_definitions(-DRELEASE_DEBUG=0)
  add_definitions(-DONLINE_DATA_COMM=0)
  add_definitions(-DUSING_FILE_TRADE_SPOT=1)
  add_definitions(-DSAVE_STOP_IDX_TO_FILE=0)
  add_definitions(-DSHMEM_READER=1)


  set(CMAKE_C_FLAGS_DEBUG "-Wall -g")
  set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g")
  set(CMAKE_DEBUG_POSTFIX "d")
ENDIF ()


IF (CMAKE_BUILD_TYPE MATCHES Release)
  message("Release build libmttrade")

  add_definitions(-DSTONE_DEBUG=0)
  add_definitions(-DSTEP_BY_STEP=0)
  add_definitions(-DRELEASE_DEBUG=0)
  add_definitions(-DONLINE_DATA_COMM=0)
  add_definitions(-DUSING_FILE_TRADE_SPOT=0)
  add_definitions(-DSAVE_STOP_IDX_TO_FILE=0)
  add_definitions(-DSHMEM_READER=1)

  
  set(CMAKE_C_FLAGS "-Wall -pipe -m64 -O3 -flto=auto -ffast-math -march=native -funroll-loops -fomit-frame-pointer")
  set(CMAKE_CXX_FLAGS "-Wall -pipe -m64 -O3 -flto=auto -ffast-math -march=native -funroll-loops -fomit-frame-pointer")

ENDIF ()

set (LIBTRADE mttrade)
add_library(${LIBTRADE} SHARED 
  include/types.h
  include/circle-array.h
  include/channel.h
  include/dirs.hpp
  include/energy.hpp
  include/fighting.hpp
  include/force-dir.hpp
  include/lines.hpp
  include/log.h
  include/mockif.hpp
  include/position.hpp
  include/schrodinger.hpp
  include/spacetime.hpp
  include/strategy.hpp
  include/strategy-00.hpp
  include/td_signal.hpp
  include/tick.h
  include/tjm_action.hpp
  include/turn.hpp
  include/trigger.hpp
  include/params.hpp
  include/wave.hpp
  include/wfw.hpp
  include/money-tree.hpp
  include/opportunity.hpp
  include/swing.hpp
  include/udp.h
  src/circle-array.c
  src/channel.c
  src/dirs.cpp
  src/fighting.cpp
  src/force-dir.cpp
  src/lines.cpp
  src/log.c
  src/mockif.cpp
  src/opportunity.cpp
  src/position.cpp
  src/schrodinger.cpp
  src/spacetime.cpp
  src/strategy.cpp
  src/strategy-00.cpp
  src/td_signal.cpp
  src/tick.c
  src/tjm_action.cpp
  src/turn.cpp
  src/trigger.cpp
  src/params.cpp
  src/wave.cpp
  src/wfw.cpp
  src/money-tree.cpp
  src/swing.cpp
  src/udp.c
)

target_compile_definitions(${LIBTRADE} PRIVATE _UNIX)

target_link_libraries(${LIBTRADE} pthread)

install(TARGETS ${LIBTRADE}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR})


set (BT mtrader)
set (SHMEM shmem)

IF (CMAKE_BUILD_TYPE MATCHES Debug)
  message("Debug build mtraderd")

  add_executable(${BT}d src/mtrader.cpp)
  target_compile_definitions(${BT}d PRIVATE _UNIX)
  target_link_libraries(${BT}d ${LIBTRADE}d)
  install(TARGETS ${BT}d DESTINATION ${BIN_INSTALL_DIR})

  add_executable(${SHMEM}d src/shared.cpp)
  target_compile_definitions(${SHMEM}d PRIVATE _UNIX)
  target_link_libraries(${SHMEM}d ${LIBTRADE}d)
  install(TARGETS ${SHMEM}d DESTINATION ${BIN_INSTALL_DIR})
ENDIF ()

IF (CMAKE_BUILD_TYPE MATCHES Release)
  message("Release build mtrader")
  add_executable(${BT} src/mtrader.cpp)
  target_compile_definitions(${BT} PRIVATE _UNIX)
  target_link_libraries(${BT} ${LIBTRADE})
  install(TARGETS ${BT} DESTINATION ${BIN_INSTALL_DIR})


  add_executable(${SHMEM} src/shared.cpp)
  target_compile_definitions(${SHMEM} PRIVATE _UNIX)
  target_link_libraries(${SHMEM} ${LIBTRADE})
  install(TARGETS ${SHMEM} DESTINATION ${BIN_INSTALL_DIR})
ENDIF ()
